//package com.nkym.config;/*
// * @ClassName RocketMQConfig
// * @Desc TODO
// * @Author 19637
// * @Date 2023/5/19 20:51
// * @Version 1.0
// */
//
//import cn.hutool.extra.mail.MailUtil;
//import com.google.gson.Gson;
//import com.nkym.constants.UserConstant;
//import com.nkym.pojo.dto.user.UserAddRequest;
//import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
//import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
//import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
//import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
//import org.apache.rocketmq.client.exception.MQClientException;
//import org.apache.rocketmq.client.producer.DefaultMQProducer;
//import org.apache.rocketmq.common.message.MessageExt;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.nio.charset.StandardCharsets;
//import java.util.List;
//
//@Configuration
//public class RocketMQConfig {
//
//    @Value("${com.nkym.rocketmq.nameserver}")
//    private String nameServer;
//
//    @Bean("emailProducer")
//    public DefaultMQProducer emailProducer() throws MQClientException {
//        DefaultMQProducer producer = new DefaultMQProducer(UserConstant.USER_GROUP);
//        //nameserver 地址
//        producer.setNamesrvAddr(nameServer);
//        //实例名
//        producer.setInstanceName(UserConstant.USER_REGISTER_INSTANCE);
//        producer.start();
//        return producer;
//    }
//
//    @Bean("emailConsumer")
//    public DefaultMQPushConsumer emailConsumer() throws MQClientException {
//        DefaultMQPushConsumer emailConsumer = new DefaultMQPushConsumer(UserConstant.USER_GROUP);
//        emailConsumer.setNamesrvAddr(nameServer);
//        emailConsumer.subscribe(UserConstant.USER_REGISTER_TOPIC, "*");
//        emailConsumer.setMessageListener(new MessageListenerConcurrently() {
//            @Override
//            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
//                MessageExt messageExt = list.get(0);
//                if (messageExt == null) {
//                    return ConsumeConcurrentlyStatus.RECONSUME_LATER;
//                }
//                String jsonData = new String(messageExt.getBody(), StandardCharsets.UTF_8);
//                UserAddRequest userAddRequest = new Gson().fromJson(jsonData, UserAddRequest.class);
//                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
//            }
//        });
//        return emailConsumer;
//    }
//
//
//}
